﻿@using WsdShop.Model.Enum
@{
    Layout = "";
}
<style>
    .my-drop-zone {
        border: dotted 3px lightgray;
    }

    .nv-file-over {
        border: dotted 3px red;
    }
    /* Default class applied to drop zones on over */
    .another-file-over-class {
        border: dotted 3px green;
    }

    html, body {
        height: 100%;
    }

    canvas {
        background-color: #f3f3f3;
        -webkit-box-shadow: 3px 3px 3px 0 #e3e3e3;
        -moz-box-shadow: 3px 3px 3px 0 #e3e3e3;
        box-shadow: 3px 3px 3px 0 #e3e3e3;
        border: 1px solid #c3c3c3;
        height: 100px;
        margin: 6px 0 0 6px;
    }

    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 55% !important;
    }

    .form-horizontal .form-group {
        margin-left: 0;
        margin-right: 0;
    }

    .note-image-input {
        margin-bottom: 15px;
    }
</style>

<link href="~/Content/plugins/umeditor/themes/default/css/umeditor.css" rel="stylesheet" />
<script src="~/Content/plugins/umeditor/umeditor.config.js"></script>
<script src="~/Content/plugins/umeditor/umeditor.min.js"></script>
<script src="~/Content/plugins/umeditor/lang/zh-cn/zh-cn.js"></script>
<div ng-controller="ProductEditController">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-12">
                <form name="formValidate" ng-submit="submitForm()" novalidate="" class="form-validate form-horizontal">
                    <!-- START 基本信息panel-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0">
                                <legend>基本信息</legend>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">商品名称</label>
                                    <div class="col-sm-4">
                                        <div class="form-inline">
                                            <input style="width: 70%;" type="text" name="name" required="" ng-model="NormalSaleProduct.Name" class="form-control" maxlength="200" />
                                        </div>
                                        <span ng-show="validateInput('name', 'required')" class="text-danger">请输入商品名称</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">商品描述</label>
                                    <div class="col-sm-4">
                                        <textarea rows="4" ng-model="NormalSaleProduct.Description" class="form-control" maxlength="500"></textarea>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">所属分类</label>
                                    <div class="col-sm-6">
                                        <div class="form-inline">
                                            <select ng-options="m.Id as m.CategoryName for m in FirstCategoryList" ng-model="NormalSaleProduct.FirstCategoryId" ng-change="GetSecondCategory()" class="form-control">
                                                <option value="">请选择一级分类</option>
                                            </select>
                                            <select ng-options="m.Id as m.CategoryName for m in SecondCategoryList" ng-model="NormalSaleProduct.CategoryId" class="form-control">
                                                <option value="">请选择二级分类</option>
                                            </select>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            @*<fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">购买可得积分值</label>
                                    <div class="col-sm-1">
                                        <input type="number" ng-model="NormalSaleProduct.Points" class="form-control" name="points" maxlength="8"
                                               ng-pattern="/^\d+$/" />
                                        <span ng-show="validateInput('points', 'pattern')" class="text-danger">请填写正确的积分值</span>
                                    </div>

                                </div>
                            </fieldset>*@
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">是否参与积分抵扣</label>
                                    <div class="col-sm-2">
                                        <label class="radio-inline c-radio">
                                            <input type="radio" ng-value="{{true}}" ng-model="NormalSaleProduct.IsAllowUsePoints" />
                                            <span class="fa fa-circle"></span>是
                                        </label>
                                        <label class="radio-inline c-radio">
                                            <input type="radio" ng-value="{{false}}" ng-model="NormalSaleProduct.IsAllowUsePoints" />
                                            <span class="fa fa-circle"></span>否
                                        </label>
                                    </div>
                                    <div class="col-sm-6">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">积分抵扣率(最终按会员折扣价抵扣)</label>
                                    <div class="col-sm-2">
                                        <div class="form-inline">
                                            <input percent type="number" name="sellRate" required="" ng-model="NormalSaleProduct.UsePointRate" class="form-control" ng-pattern="/^(\d{1,2}(\.\d{1,2})?|100)$/" maxlength="6" />
                                            %
                                        </div>
                                        <span ng-show="validateInput('sellRate', 'required')" class="text-danger">请填写积分抵扣率</span>
                                        <span ng-show="validateInput('sellRate', 'pattern')" class="text-danger">您设置的积分抵扣率异常，请重新设置</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">销量</label>
                                    <div class="col-sm-2">
                                        <div class="form-inline">
                                            <input percent type="number" name="SaleCount" required="" ng-model="NormalSaleProduct.SaleCount" class="form-control" maxlength="20" />
                                        </div>
                                        <span ng-show="validateInput('sellRate', 'required')" class="text-danger">请填写销量</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">是否使用优惠券</label>
                                    <div class="col-sm-2">
                                        <label class="radio-inline c-radio">
                                            <input type="radio" ng-value="{{true}}" ng-model="NormalSaleProduct.IsAllowUseCoupon" />
                                            <span class="fa fa-circle"></span>是
                                        </label>
                                        <label class="radio-inline c-radio">
                                            <input type="radio" ng-value="{{false}}" ng-model="NormalSaleProduct.IsAllowUseCoupon" />
                                            <span class="fa fa-circle"></span>否
                                        </label>
                                    </div>
                                    <div class="col-sm-6">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">是否推荐</label>
                                    <div class="col-sm-2">
                                        <label class="radio-inline c-radio">
                                            <input type="radio" ng-value="{{true}}" ng-model="NormalSaleProduct.IsRecommend" />
                                            <span class="fa fa-circle"></span>是
                                        </label>
                                        <label class="radio-inline c-radio">
                                            <input type="radio" ng-value="{{false}}" ng-model="NormalSaleProduct.IsRecommend" />
                                            <span class="fa fa-circle"></span>否
                                        </label>
                                    </div>
                                    <div class="col-sm-6">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            @*<fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">是否配置配送区域</label>
                                    <div class="col-sm-2">
                                        <label class="radio-inline c-radio">
                                            <input type="radio" ng-value="{{true}}" ng-model="NormalSaleProduct.IsConfigArea" />
                                            <span class="fa fa-circle"></span>是
                                        </label>
                                        <label class="radio-inline c-radio">
                                            <input type="radio" ng-value="{{false}}" ng-model="NormalSaleProduct.IsConfigArea" />
                                            <span class="fa fa-circle"></span>否
                                        </label>
                                    </div>
                                    <div class="col-sm-2">
                                        <button type="button" class="mb-sm btn btn-info" ng-show="NormalSaleProduct.IsConfigArea" ng-click="positionManagementView(1)">
                                            配置配送区域
                                        </button>
                                    </div>
                                    <div class="col-sm-4">
                                        
                                    </div>
                                </div>
                            </fieldset>*@
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">排序</label>
                                    <div class="col-sm-1">
                                        <input class="form-control" maxlength="8" ng-model="NormalSaleProduct.Sort" type="number">
                                    </div>
                                    <div class="col-sm-6">
                                        <div class="text-danger form-control-static">数字越大显示在前台列表最前面，不填默认排序0，排序相同按照时间倒序</div>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">商品主图</label>
                                    <div class="col-sm-2">
                                        <div class="imgcrop-preview">
                                            <img ng-src="{{myCroppedImage}}" style="max-width: 100%; max-height: 100%" onerror="javascript: this.src = '/Content/img/default.png';" />
                                            <input id="fileInput" class="ng-hide" type="file" nv-file-select="" uploader="uploader" />
                                        </div>
                                        <div>
                                            <div style="" class="progress progress-xs" ng-show="uploading">
                                                <div role="progressbar" ng-style="{ 'width': uploader.progress + '%' }" class="progress-bar"></div>
                                            </div>
                                        </div>
                                        <span ng-show="IsCheckedPic" class="text-danger">请选择商品主图</span>
                                    </div>
                                    <div class="col-sm-4">
                                        <button type="button" class="mb-sm btn btn-info" id="selectImage">
                                            图片选择
                                        </button>
                                        <span class="text-danger">建议尺寸：640x640</span>
                                    </div>
                                    <div class="col-sm-2">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">商品附属图</label>
                                    <div class="col-sm-1" ng-repeat="imgUrl in NormalSaleProduct.SubImgUrls track by $index">
                                        <img src="/Content/img/pro_detail_03.png"
                                             style="position: absolute; width: 23px; height: 23px; right: 5px; top: -6px;"
                                             ng-click="croppedImageList.splice($index,1);NormalSaleProduct.SubImgUrls.splice($index,1)">
                                        <img ng-src="{{ImgHostUrl + imgUrl}}" style="max-width: 100%; max-height: 100%" onerror="javascript: this.src =  '/Content/img/default.png';" />
                                    </div>
                                    <div class="col-sm-2">
                                        <input type="hidden" id="uploadFlag" />
                                        <button type="button" class="mb-sm btn btn-info" id="selectImageSub" ng-show="croppedImageList.length<5">
                                            添加图片
                                        </button>
                                    </div>
                                    <div class="col-sm-4">
                                        <span class="text-danger">建议尺寸：320x320,最多5张</span>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                    </div>
                    <!-- END panel-->
                    <!--规格-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0">
                                <legend>商品规格</legend>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">规格类型 <a ng-click="refreshSpec()" class="btn btn-primary btn-xs" data-original-title="刷新规格" title="" data-toggle="tooltip"><i class="fa fa-refresh"></i></a></label>
                                    <div class="col-sm-2">
                                        <select ng-options="m.Id as m.SpecTypeName for m in SpecTypeList" ng-model="NormalSaleProduct.SpecTypeId" ng-change="ChangeSpecType()" class="form-control">
                                            <option value="">请选择规格类型</option>
                                        </select>
                                        
                                    </div>
                                    <div class="col-sm-1">
                                        <h4 class="text-danger">*</h4>
                                    </div>
                                    <div class="col-sm-4">
                                    <button type="button" class="mb-sm btn btn-info" id="selectImage" ng-click="UpdataView()" @*onclick="window.open('http://admin.youpinsanyue.com/#/app/product/specType')*@">
                                        新增规格类型
                                    </button>
                                    <button type="button" class="mb-sm btn btn-info" id="selectImage" ng-click="addSpec()" @*onclick="window.open('http://admin.youpinsanyue.com/#/app/product/specTemplate')"*@>
                                        新增规格
                                    </button>
                                    <button type="button" class="mb-sm btn btn-info" id="selectImage" ng-click="addSpecItem()" @*onclick="window.open('http://admin.youpinsanyue.com/#/app/product/specTemplate')"*@>
                                        新增规格项
                                    </button>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">选择规格</label>
                                    <div class="col-sm-10">
                                        <div class="table-responsive">
                                            <table class="table table-striped table-bordered table-hover">
                                                <thead>
                                                    <tr ng-repeat="spectemp in SpecTemplateResponse | orderBy:'Id' ">
                                                        <th>{{spectemp.SpecName}}</th>
                                                        <td>
                                                            <span ng-repeat="specitem in spectemp.SpecItemResponseList | orderBy:'Id' ">
                                                                <button type="button" ng-class="GetMyclass(specitem)" ng-click="ChooseSpecItem(specitem)">{{specitem.SpecItemName}}</button>
                                                                @*<button type="button" class="mb-sm btn btn-success" ng-show="ChooseSpecItemList.indexOf(specitem)>-1" ng-click="ChooseSpecItem(specitem)">{{specitem.SpecItemName}}</button>*@
                                                            </span>
                                                        </td>
                                                    </tr>
                                                </thead>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">规格信息</label>
                                    <div class="col-sm-10">
                                        <div class="table-responsive">
                                            <table class="table table-striped table-bordered table-hover">
                                                <colgroup>
                                                    <col ng-repeat="spectemplate in ChooseSpecTemplateList | orderBy:'Id' " style="width:8%;" />
                                                    <col style="width:9%;" />
                                                    <col style="width:5%;" />
                                                    <col style="width:9%;" />
                                                    <col style="width:9%;" />
                                                    <col style="width:9%;" />
                                                    <col style="width:12%;" />
                                                    <col style="width:10%;" />
                                                </colgroup>
                                                <thead>
                                                    <tr>
                                                        <th ng-repeat="spectemplate in ChooseSpecTemplateList | orderBy:'Id' ">{{spectemplate.SpecName}}</th>
                                                        <th>库存</th>
                                                        <th>可销库存</th>
                                                        <th>成本价</th>
                                                        <th>市场价</th>
                                                        <th>销售价</th>
                                                        <th>条形码</th>
                                                        <th>重量（克，可不填）</th>
                                                    </tr>
                                                </thead>
                                                <tbody>
                                                    <tr ng-repeat="spec in SpecList">
                                                        <td ng-repeat="specitem in spec.SpecItemList | orderBy:'SpecTemplateId' ">
                                                            {{specitem.SpecItemName}}
                                                        </td>
                                                        <td>
                                                            <input class="form-control" maxlength="8" ng-change="CalculateTotalStock()" required="" ng-model="spec.Stock" type="number" name="stock{{$index}}" ng-pattern="/^\d+$/">
                                                            <span ng-show="validateInput('stock'+$index, 'required')" class="text-danger">请填写库存</span>
                                                            <span ng-show="validateInput('stock'+$index, 'pattern')" class="text-danger">请输入正确的库存</span>
                                                        </td>
                                                        <td>
                                                            {{spec.Stock - spec.WaitSendStock}}
                                                        </td>
                                                        <td>
                                                            <input class="form-control" maxlength="8" ng-model="spec.CostPrice" type="text" name="costPrice{{$index}}" ng-pattern="/^(([0-9]|([1-9][0-9]{0,9}))((\.[0-9]{1,2})?))$/">
                                                            @*<span ng-show="validateInput('marketPrice'+$index, 'required')" class="text-danger">请填写成本价</span>*@
                                                            <span ng-show="validateInput('costPrice'+$index, 'pattern')" class="text-danger">请输入正确的成本价</span>
                                                        </td>
                                                        <td>
                                                            <input class="form-control" maxlength="8" ng-model="spec.MarketPrice" type="text" name="marketPrice{{$index}}" ng-pattern="/^(([0-9]|([1-9][0-9]{0,9}))((\.[0-9]{1,2})?))$/">
                                                            @*<span ng-show="validateInput('marketPrice'+$index, 'required')" class="text-danger">请填写{{NormalSaleProduct.PriceTag == undefined || NormalSaleProduct.PriceTag == '' ? '市场价' : NormalSaleProduct.PriceTag}}</span>*@
                                                            <span ng-show="validateInput('marketPrice'+$index, 'pattern')" class="text-danger">请输入正确的市场价</span>
                                                        </td>
                                                        <td>
                                                            <input class="form-control" maxlength="8" required="" ng-model="spec.Price" type="text" name="price{{$index}}" ng-pattern="/^(([0-9]|([1-9][0-9]{0,9}))((\.[0-9]{1,2})?))$/">
                                                            <span ng-show="validateInput('price'+$index, 'required')" class="text-danger">请填写销售价</span>
                                                            <span ng-show="validateInput('price'+$index, 'pattern')" class="text-danger">请输入正确的销售价</span>
                                                        </td>
                                                        <td>
                                                            <input class="form-control" maxlength="20" ng-model="spec.BarCode" type="text" name="barCode{{$index}}">
                                                        </td>
                                                        <td>
                                                            <input class="form-control" maxlength="8" ng-model="spec.ProductWeight" type="text" name="productWeight{{$index}}" ng-pattern="/^[0-9]+(.[0-9]{1})?$/">
                                                            <span ng-show="validateInput('productWeight'+$index, 'pattern')" class="text-danger">请输入正确的重量</span>
                                                        </td>
                                                    </tr>
                                                </tbody>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">总库存</label>
                                    <div class="col-sm-2">
                                        <input type="text" ng-model="totalStock" readonly="readonly" class="form-control" />
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                    </div>
                    <!--详情-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
                        <div class="panel-body">
                            <fieldset class="b0">
                                <legend>商品详情</legend>
                            </fieldset>
                            <fieldset>
                                <div class="col-sm-1"></div>
                                <div class="col-sm-10">
                                    @*<summernote height="400" ng-model="NormalSaleProduct.Detail" on-image-upload="summernoteImgUpload(files)"></summernote>*@
                                    <script type="text/plain" id="Detail" name="Detail" style="height: 400px; width:90%" ng-bind="NormalSaleProduct.Detail" >
                                    </script>
                                </div>
                            </fieldset>
                        </div>
                    </div>
                    <!--运费模版-->
                    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading }">
                        <div class="panel-body">
                            <fieldset class="b0">
                                <legend>物流服务</legend>
                            </fieldset>
                            <fieldset>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label">运费设置</label>
                                    <div class="col-sm-1" style="width: 150px;">
                                        <div class="radio c-radio">
                                            <label>
                                                <input type="radio" required="" name="freightradio" ng-click="ChooseFreightRadio()" value="0" ng-model="NormalSaleProduct.SetFreightType" class="ng-dirty ng-valid ng-valid-required ng-touched ng-valid-parse">
                                                <span class="fa fa-circle"></span>全国统一运费
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <input class="form-control" id="uniformfreightinput" maxlength="8" ng-model="NormalSaleProduct.UniformFreight" type="number">
                                    </div>
                                    <div class="col-sm-1">
                                        <label class="col-sm-1 control-label">元</label>
                                    </div>
                                </div>
                                <br />
                                <div class="form-group">
                                    <label class="col-sm-2 control-label"><a ng-click="refreshTemplate()" class="btn btn-primary btn-xs" data-original-title="刷新模版" title="" data-toggle="tooltip"><i class="fa fa-refresh"></i></a></label>
                                    <div class="col-sm-1" style="width:150px;">
                                        <div class="radio c-radio">
                                            <label>
                                                <input type="radio" required="" ng-click="ChooseFreightRadio()" name="freightradio" value="1" ng-model="NormalSaleProduct.SetFreightType" class="ng-dirty ng-valid ng-valid-required ng-touched ng-valid-parse">
                                                <span class="fa fa-circle"></span>选择运费模版
                                            </label>
                                        </div>
                                    </div>
                                    <div class="col-sm-2">
                                        <select ng-options="m.Id as m.TemplateName for m in FreightList" id="choosefreighttemplate" ng-model="NormalSaleProduct.FreightTemplateId" ng-change="GetFreightInfo(NormalSaleProduct.FreightTemplateId)" class="form-control">
                                            <option value="">请选择模版</option>
                                        </select>
                                    </div>
                                    <div class="col-sm-2">
                                        <button type="button" class="mb-sm btn btn-info" id="selectImage"  onclick="window.open('http://admin.youpinsanyue.com/#/app/product/freightManage')">
                                            新增模版
                                        </button>
                                    </div>
                                </div>
                            </fieldset>
                            <fieldset ng-show="NormalSaleProduct.FreightTemplateId>0">
                                <label class="col-sm-2 control-label"></label>
                                <div class="col-sm-9">
                                    <div class="panel panel-default" style="width: 80%;">
                                        <div class="panel-heading">
                                            <label class="text-left">
                                                {{FreightInfo.TemplateName}}
                                            </label>
                                        </div>
                                        <div class="panel-body">
                                            <table border="0" cellspacing="0" cellpadding="0" width="100%" class="table table-striped table-bproducted table-hover" ng-if="FreightInfo.FreightType==@(EnumFreightTemplateType.按重量.GetHashCode())">
                                                <tr>
                                                    <th width="35%">配送区域</th>
                                                    <th width="10%">首重(克)</th>
                                                    <th width="10%">首费(元)</th>
                                                    <th width="10%">续重(克)</th>
                                                    <th width="10%">续费(元)</th>
                                                    <th width="25%">指定条件包邮(选填)</th>
                                                </tr>
                                                <tr ng-repeat="detail in FreightInfo.FreightDetail">
                                                    <td>
                                                        <span ng-repeat="province in detail.AreaNames">
                                                            <span class="mr-sm label label-primary ng-binding">{{province}}</span>
                                                        </span>
                                                    </td>
                                                    <td>{{detail.FirstCount}}</td>
                                                    <td>{{detail.FirstMoney}}</td>
                                                    <td>{{detail.ContiCount}}</td>
                                                    <td>{{detail.ContiMoney}}</td>
                                                    <td>{{detail.FullCount>0?'重量'+detail.FullCount+'克（含）以内包邮':'无'}}</td>
                                                </tr>
                                            </table>
                                            <table border="0" cellspacing="0" cellpadding="0" width="100%" class="table table-striped table-bproducted table-hover" ng-if="FreightInfo.FreightType==@(EnumFreightTemplateType.按地区.GetHashCode())">
                                                <tr>
                                                    <th width="50%">配送区域</th>
                                                    <th width="15%">运费(元)</th>
                                                    <th width="35%">指定条件包邮(选填)</th>
                                                </tr>
                                                <tr ng-repeat="detail in FreightInfo.FreightDetail">
                                                    <td>
                                                        <span ng-repeat="province in detail.AreaNames">
                                                            <span class="mr-sm label label-primary ng-binding">{{province}}</span>
                                                        </span>
                                                    </td>
                                                    <td>{{detail.FirstMoney}}</td>
                                                    <td>{{detail.FullCount>0?'满'+detail.FullCount+'元（含）包邮':'无'}}</td>
                                                </tr>
                                            </table>
                                            <table border="0" cellspacing="0" cellpadding="0" width="100%" class="table table-striped table-bproducted table-hover" ng-if="FreightInfo.FreightType==@(EnumFreightTemplateType.无条件包邮.GetHashCode())">
                                                <tr>
                                                    <th>配送区域</th>
                                                    <th>运费(元)</th>
                                                </tr>
                                                <tr>
                                                    <td>全国统一运费</td>
                                                    <td>0</td>
                                                </tr>
                                            </table>
                                        </div>
                                    </div>
                                </div>
                            </fieldset>
                        </div>
                    </div>
                    <div class="text-right">
                        <button type="button" class="btn btn-warning" ng-click="cancel()">返回列表</button>
                        <button type="button" class="btn btn-info" ng-click="saveNormalProduct()">保 存</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/ng-template" id="setUpTempDialogId">
    <div class="ngdialog-message">
        <div class="panel panel-default">
            <div class="panel-body">
                <fieldset class="b0">
                    <legend>添加规格类型</legend>
                </fieldset>
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">类型名称</label>
                        <div class="col-sm-6">
                            <input type="text" name="Name" required="" maxlength="25" ng-model="Position.SpecTypeName" class="form-control" />
                        </div>
                        <div class="col-sm-1">
                            <h4 class="text-danger">*</h4>
                        </div>
                    </div>
                </fieldset>
                <div class="panel-footer text-right">
                    <button type="button" class="btn btn-default" ng-click="closeThisDialog()">
                        关闭
                    </button>
                    <button type="button" class="btn btn-default" ng-click="serveThisMessage()">
                        确定
                    </button>
                </div>
            </div>
        </div>
    </div>
</script>

<script type="text/ng-template" id="specId">
    <div class="ngdialog-message">
        <div class="panel panel-default">
            <div class="panel-body">
                <fieldset class="b0">
                    <legend>添加规格</legend>
                </fieldset>
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">规格名称</label>
                        <div class="col-sm-6">
                            <input type="text" name="Name" required="" maxlength="25" ng-model="Spec.SpecName" class="form-control" />
                        </div>
                        <div class="col-sm-1">
                            <h4 class="text-danger">*</h4>
                        </div>
                    </div>
                </fieldset>
                <div class="panel-footer text-right">
                    <button type="button" class="btn btn-default" ng-click="closeThisDialog()">
                        关闭
                    </button>
                    <button type="button" class="btn btn-default" ng-click="saveSpec()">
                        确定
                    </button>
                </div>
            </div>
        </div>
    </div>
</script>


<script type="text/ng-template" id="specItemId">
    <div class="ngdialog-message">
        <div class="panel panel-default">
            <div class="panel-body">
                <fieldset class="b0">
                    <legend>添加规格项</legend>
                </fieldset>
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">规格</label>
                        <div class="col-sm-6">
                            <select ng-options="m.Id as m.SpecName for m in SpecTemplateResponse" ng-model="SpecItem.SpecTemplateId" class="form-control">
                                <option value="">请选择规格</option>
                            </select>
                        </div>
                        <div class="col-sm-1">
                            <h4 class="text-danger">*</h4>
                        </div>
                    </div>
                </fieldset>
                <fieldset>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">规格项</label>
                        <div class="col-sm-6">
                            <input type="text" name="Name" required="" maxlength="25" ng-model="SpecItem.SpecItemName" class="form-control" />
                        </div>
                        <div class="col-sm-1">
                            <h4 class="text-danger">*</h4>
                        </div>
                    </div>
                </fieldset>
                <div class="panel-footer text-right">
                    <button type="button" class="btn btn-default" ng-click="closeThisDialog()">
                        关闭
                    </button>
                    <button type="button" class="btn btn-default" ng-click="saveSpecItem()">
                        确定
                    </button>
                </div>
            </div>
        </div>
    </div>
</script>

<script type="text/ng-template" id="getJurisdictionDialogId">
    <div class="ngdialog-message">
        <div class="panel panel-default">
            <div class="panel-body">
                <fieldset class="b0">
                    <legend>配置配送区域</legend>
                </fieldset>
                <fieldset>
                    <div id="authTree" js-tree="vm.treeConfig" should-apply="vm.applyModelChanges()" ng-model="vm.treeData" tree="vm.treeInstance" tree-events="ready:vm.readyCB;create_node:vm.createCB"></div>
                </fieldset>
                <div class="panel-footer text-right">
                    <button type="button" class="btn btn-default" ng-click="closeThisDialog()">
                        关闭
                    </button>
                    <button type="button" class="btn btn-default" ng-click="serveRootMessage()">
                        确定
                    </button>
                    <button type="button" style="display:none" class="btn btn-default" ng-click="getChecked()">
                        获取
                    </button>
                </div>
            </div>
        </div>
    </div>
</script>

<script type="text/javascript">
   

    App.controller('ProductEditController', ["$scope", "$state", "$http", "$stateParams", "Notify", "FileUploader", 'ngTableParams', 'ngTableDataService', 'ngDialog', '$filter', '$rootScope', '$timeout', 'toaster',
        function ($scope, $state, $http, $stateParams, Notify, FileUploader, ngTableParams, ngTableDataService, ngDialog, $filter, $rootScope,$timeout, toaster) {
            'use strict';
            $scope.submitted = false;
            $scope.isLoading = true;
            $scope.IsCheckedPic = false;
            $scope.croppedImageList = [];
            $scope.NormalSaleProduct = {};
            $scope.NormalSaleProduct.IsConfigArea = false;
            $scope.validateInput = function (name, type) {
                var input = $scope.formValidate[name];
                return (input.$dirty || $scope.submitted) && input.$error[type];
            };

            //计算总库存
            var calculateTotalStock = $scope.CalculateTotalStock = function () {
                $scope.totalStock = 0;
                if ($scope.SpecList) {
                    $scope.SpecList.forEach(function (e) {
                        $scope.totalStock += e.Stock;
                    });
                }
            }

            var um;
            var tt = function () {
                um == UM.getEditor('Detail');
            }

            setTimeout(tt, 1000);

            //var quill = new Quill('#editor', {
            //    modules: {
            //        toolbar: [
            //          [{ header: [1, 2, false] }],
            //          ['bold', 'italic', 'underline'],
            //          ['image', 'code-block']
            //        ]
            //    },
            //    placeholder: 'Compose an epic...',
            //    theme: 'snow'  // or 'bubble'
            //});


            //数据初始化
            $http.post("/Product/ProductEdit", { Sku: $stateParams.Id }).then(function (response) {
                $scope.NormalSaleProduct = response.data.ProductMain;
                $scope.SpecTypeList = response.data.SpecTypeList;
                $scope.ChooseSpecTemplateList = response.data.ChooseSpecTemplateList;
                $scope.ChooseSpecItemList = response.data.ChooseSpecItemList;
                $scope.CategoryList = response.data.CategoryList;
                $scope.FirstCategoryList = $filter('filter')(response.data.CategoryList, function (item) { return item.ParentId === 0; });
                $scope.FreightList = response.data.FreightList;
                $scope.SpecTemplateResponse = response.data.SpecTemplateResponse;
                $scope.SpecList = response.data.SpecList;

                
                $scope.GetMyclass = function (specitem) {
                    //console.log(specitem);
                    var sss = $filter('filter')($scope.ChooseSpecItemList, function (item) { return item.Id === specitem.Id; });
                    return 'mb-sm btn btn-' + (sss.length > 0 ? 'success' : 'default');
                }

                //获取二级分类
                $scope.GetSecondCategory = function () {
                    $scope.SecondCategoryList = $filter('filter')($scope.CategoryList, function (item) { return item.ParentId === $scope.NormalSaleProduct.FirstCategoryId; });
                }

                $scope.GetSecondCategory();

                if (!$scope.NormalSaleProduct) {
                    $scope.NormalSaleProduct = {
                        IsAllowUsePoints: false,
                        Points: 0
                    };
                } else {
                    $scope.myCroppedImage = $rootScope.ImgHostUrl + angular.copy($scope.NormalSaleProduct.ImgUrl);
                    if ($scope.NormalSaleProduct.SubImgUrls) {
                        angular.forEach($scope.NormalSaleProduct.SubImgUrls, function (value, index) {
                            $scope.croppedImageList.push($rootScope.ImgHostUrl + value);
                        });
                    }
                }

                calculateTotalStock();

                if (!$scope.FreightList) {
                    $scope.FreightList = [];
                }
                if ($scope.NormalSaleProduct.FreightTemplateId > 0) {
                    $scope.GetFreightInfo($scope.NormalSaleProduct.FreightTemplateId);
                }

                $scope.ChooseFreightRadio();
                $scope.isLoading = false;
            });

            
            $scope.addSpec = function () {
                if ($scope.NormalSaleProduct.SpecTypeId > 0) {

                    $scope.Spec = {};

                    ngDialog.openConfirm({
                        template: 'specId',
                        className: 'ngdialog-theme-plain',
                        scope: $scope
                    }).then(function (value) {
                    }, function (reason) {
                    }
                    );
                }
                else {
                    Notify.alert('请选择规格类型', { status: 'warning' });
                }
            }

            $scope.addSpecItem = function () {
                if ($scope.NormalSaleProduct.SpecTypeId > 0) {

                    $scope.SpecItem = {};

                    ngDialog.openConfirm({
                        template: 'specItemId',
                        className: 'ngdialog-theme-plain',
                        scope: $scope
                    }).then(function (value) {
                    }, function (reason) {
                    }
                    );
                }
                else {
                    Notify.alert('请选择规格类型', { status: 'warning' });
                }
            }

            //跳转更新新增页面
            $scope.UpdataView = function () {
                    $scope.Position = {};
               
                ngDialog.openConfirm({
                    template: 'setUpTempDialogId',
                    className: 'ngdialog-theme-plain',
                    scope: $scope
                }).then(function (value) {
                }, function (reason) {
                }
                );
            }
            //确认点击
            $scope.serveThisMessage = function () {

                if ($scope.Position.SpecTypeName == null || $scope.Position.SpecTypeName.length <= 0) {
                    Notify.alert('请输入规格类型名称!', { status: 'warning', timeout: 1000 });
                    return false;
                }

                $http.post("/Product/SpecTypeEdit", { specType: $scope.Position }).then(function (returnData) {
                    if (returnData.data.isSuccess) {
                        
                        Notify.alert('操作成功!', { status: 'success' });
                        ngDialog.closeAll();
                        $http.post("/Product/GetProductSpecType", { Sku: $stateParams.Id }).then(function (response) {
                            if (response.data.isSuccess) {
                                $scope.SpecTypeList = response.data.data;
                                //if ($scope.NormalSaleProduct.SpecTypeId > 0) {
                                //    $http.post("/Product/ChangeSpecType", { Sku: $stateParams.Id, specTypeId: $scope.NormalSaleProduct.SpecTypeId }).then(function (response) {
                                //        $scope.SpecTemplateResponse = response.data.SpecTemplateResponse;
                                //        $scope.SpecList = response.data.SpecList;
                                //        $scope.ChooseSpecTemplateList = response.data.ChooseSpecTemplateList;
                                //        $scope.ChooseSpecItemList = response.data.ChooseSpecItemList;
                                //    });
                                //}

                            }
                            else {
                                Notify.alert(response.data.msg, { status: 'warning' });
                            }
                        });
                    } else {
                        Notify.alert(returnData.data.msg, { status: 'warning' });
                    }
                });
            }

            $scope.saveSpec = function () {
                $scope.Spec.SpecTypeId = $scope.NormalSaleProduct.SpecTypeId;

               
                if ($scope.Spec.SpecName == null || $scope.Spec.SpecName.length <= 0) {
                    Notify.alert('请输入规格名称!', { status: 'warning', timeout: 1000 });
                    return false;
                }
                $http.post("/Product/SpecTemplateEdit", { specTemplate: $scope.Spec }).then(function (returnData) {
                    if (returnData.data.isSuccess) {
                        ngDialog.closeAll();
                        Notify.alert('操作成功!', { status: 'success' });
                        if ($scope.NormalSaleProduct.SpecTypeId > 0) {
                            $http.post("/Product/ChangeSpecType", { Sku: $stateParams.Id, specTypeId: $scope.NormalSaleProduct.SpecTypeId }).then(function (response) {
                                $scope.SpecTemplateResponse = response.data.SpecTemplateResponse;
                                $scope.SpecList = response.data.SpecList;
                                $scope.ChooseSpecTemplateList = response.data.ChooseSpecTemplateList;
                                $scope.ChooseSpecItemList = response.data.ChooseSpecItemList;
                            });
                        }

                    } else {
                        Notify.alert(returnData.data.msg, { status: 'warning' });
                    }
                });
            }


            $scope.saveSpecItem = function () {

                if (!$scope.SpecItem.SpecTemplateId >0) {
                    Notify.alert('请选择规格!', { status: 'warning', timeout: 1000 });
                    return;
                }
                if ($scope.SpecItem.SpecItemName == null || $scope.SpecItem.SpecItemName.length <= 0) {
                    Notify.alert('请输入规格项名称!', { status: 'warning', timeout: 1000 });
                    return;
                }
                $http.post("/Product/AddSpecItem", { model: $scope.SpecItem }).then(function (returnData) {
                    if (returnData.data.isSuccess) {
                        Notify.alert('操作成功!', { status: 'success' });
                        ngDialog.closeAll();
                        if ($scope.NormalSaleProduct.SpecTypeId > 0) {
                            $http.post("/Product/ChangeSpecType", { Sku: $stateParams.Id, specTypeId: $scope.NormalSaleProduct.SpecTypeId }).then(function (response) {
                                $scope.SpecTemplateResponse = response.data.SpecTemplateResponse;
                                $scope.SpecList = response.data.SpecList;
                                $scope.ChooseSpecTemplateList = response.data.ChooseSpecTemplateList;
                                $scope.ChooseSpecItemList = response.data.ChooseSpecItemList;
                            });
                        }

                    } else {
                        Notify.alert(returnData.data.msg, { status: 'warning' });
                    }
                });
            }

            $scope.refreshSpec = function ()
            {
                $http.post("/Product/GetProductSpecType", { Sku: $stateParams.Id }).then(function (response) {
                    if (response.data.isSuccess) {
                        $scope.SpecTypeList = response.data.data;
                        if ($scope.NormalSaleProduct.SpecTypeId > 0)
                        {
                            $http.post("/Product/ChangeSpecType", { Sku: $stateParams.Id, specTypeId: $scope.NormalSaleProduct.SpecTypeId }).then(function (response) {
                                $scope.SpecTemplateResponse = response.data.SpecTemplateResponse;
                                $scope.SpecList = response.data.SpecList;
                                $scope.ChooseSpecTemplateList = response.data.ChooseSpecTemplateList;
                                $scope.ChooseSpecItemList = response.data.ChooseSpecItemList;
                            });
                        }
                        
                    }
                    else {
                        Notify.alert(response.data.msg, { status: 'warning' });
                    }
                });
            }
            // 提交
            $scope.saveNormalProduct = function () {
                $scope.submitted = true;
                $scope.isLoading = true;
                if ($scope.formValidate.$valid) {
                    if (!$scope.NormalSaleProduct.ImgUrl || $scope.NormalSaleProduct.ImgUrl == "") {
                        $scope.IsCheckedPic = true;
                        $scope.isLoading = false;
                        Notify.alert("请选择产品主图", { status: 'warning' });
                        return false;
                    }
                    if ($scope.NormalSaleProduct.CategoryId == 0 || $scope.NormalSaleProduct.CategoryId == "") {
                        $scope.isLoading = false;
                        Notify.alert("请设置产品分类", { status: 'warning' });
                        return false;
                    }
                    if ($scope.NormalSaleProduct.SpecTypeId == 0 || $scope.SpecList.length == 0) {
                        $scope.isLoading = false;
                        Notify.alert("请设置产品规格", { status: 'warning' });
                        return false;
                    }
                    if (($scope.NormalSaleProduct.SetFreightType == 1 && $scope.NormalSaleProduct.FreightTemplateId == 0) || ($scope.NormalSaleProduct.SetFreightType != 0 && $scope.NormalSaleProduct.SetFreightType != 1)) {
                        $scope.isLoading = false;
                        Notify.alert("请设置运费模版", { status: 'warning' });
                        return false;
                    }
                    if ($scope.NormalSaleProduct.SetFreightType == 0 && $scope.NormalSaleProduct.UniformFreight < 0) {
                        $scope.isLoading = false;
                        Notify.alert("统一运费不能小于0", { status: 'warning' });
                        return false;
                    }
                    if ($scope.NormalSaleProduct.SetFreightType == 0 && $("#uniformfreightinput").val() == '') {
                        $scope.isLoading = false;
                        Notify.alert("请设置统一运费", { status: 'warning' });
                        return false;
                    }

                    $scope.NormalSaleProduct.Detail = UM.getEditor('Detail').getContent();

                    $http.post("/Product/ProductEditSubmit", { ProductMain: $scope.NormalSaleProduct, SpecList: $scope.SpecList }).then(function (returnData) {
                        if (returnData.data.isSuccess) {
                            Notify.alert('操作成功!', { status: 'success', timeout: 1000 });

                            $state.go('app.productManage', $stateParams);
                        } else {
                            Notify.alert(returnData.data.msg, { status: 'warning', timeout: 1000 });
                        }
                        $scope.isLoading = false;
                    });
                } else {
                    $scope.isLoading = false;
                    Notify.alert("请将信息填写完整后提交", { status: 'warning' });
                    var scrollTop = 0;
                    var index = 0;
                    for (var name in $scope.formValidate.$error) {
                        if ($scope.formValidate.$error.hasOwnProperty(name)) {
                            if (index === 0) {
                                scrollTop = $("[name=" + $scope.formValidate.$error[name][0].$name + "]").offset().top - 100;
                            }
                            if ($("[name=" + $scope.formValidate.$error[name][0].$name + "]").offset().top - 100 < scrollTop) {
                                scrollTop = $("[name=" + $scope.formValidate.$error[name][0].$name + "]").offset().top - 100;
                            }
                            index++;
                        }
                    }
                    document.body.scrollTop = scrollTop;
                    return false;
                }
            };

            //返回列表
            $scope.cancel = function () {
                $state.go("app.productManage", $stateParams);
            }


            //-------------图片选择相关
            //主图
            $("#selectImage").click(function () {
                $("#uploadFlag").val(0);
                $("#fileInput").click();
            });
            //附属图
            $("#selectImageSub").click(function () {
                $("#uploadFlag").val(1);
                $("#fileInput").click();
            });

            var handleFileSelect = function (evt) {
                var file = $scope.uploadSelectFile = evt.currentTarget.files[0];
                if (!evt.currentTarget.files[0] || ! /image\/\w+/.test(evt.currentTarget.files[0].type)) {
                    Notify.alert('请选择图像文件', { status: 'warning' });
                    return false;
                }
                if (file.size > 1 * 1024 * 1024) {
                    Notify.alert('图片大小不能大于1MB', { status: 'warning', timeout: 3000 });
                    $scope.uploadSelectFile = null;
                    return false;
                }
                var reader = new FileReader();
                reader.onload = function (evt) {
                    $scope.$apply(function ($scope) {
                        if ($("#uploadFlag").val() == 1 && $scope.croppedImageList.length < 5) {
                            $scope.croppedImageList.push(evt.target.result);
                        } else if ($("#uploadFlag").val() == 0) {
                            $scope.myCroppedImage = evt.target.result;
                        }
                    });
                };
                if (file)
                    reader.readAsDataURL(file);
            };

            angular.element(document.querySelector('#fileInput')).on('change', handleFileSelect);
            var uploader = $scope.uploader = new FileUploader({
                url: $rootScope.ImgUploadUrl + '?PlatForm=wsd&Path=Product&CutType=320'
            });
            uploader.filters.push({
                name: 'customFilter',
                fn: function (item /*{File|FileLikeObject}*/, options) {
                    return this.queue.length < 10;
                }
            });

            // CALLBACKS

            uploader.onWhenAddingFileFailed = function (item /*{File|FileLikeObject}*/, filter, options) {
                //  console.info('onWhenAddingFileFailed', item, filter, options);
            };
            uploader.onAfterAddingFile = function (fileItem) {

                if ($scope.uploadSelectFile && /image\/\w+/.test($scope.uploadSelectFile.type) && (($("#uploadFlag").val() == 1 && $scope.croppedImageList.length < 5) || $("#uploadFlag").val() != 1)) {
                    fileItem.upload();
                } if ($("#uploadFlag").val() == 0) {
                    $scope.uploading = true;
                }

                //    console.info('onAfterAddingFile', fileItem);
            };
            uploader.onAfterAddingAll = function (addedFileItems) {
                //   console.info('onAfterAddingAll', addedFileItems);
            };
            uploader.onBeforeUploadItem = function (item) {
                // console.info('onBeforeUploadItem', item);
            };
            uploader.onProgressItem = function (fileItem, progress) {
                // console.info('onProgressItem', fileItem, progress);
            };
            uploader.onProgressAll = function (progress) {
                //  console.info('onProgressAll', progress);
            };
            uploader.onSuccessItem = function (fileItem, response, status, headers) {
                if ($("#uploadFlag").val() == 1) {
                    if (!$scope.NormalSaleProduct.SubImgUrls) {
                        $scope.NormalSaleProduct.SubImgUrls = [];
                    }
                    $scope.NormalSaleProduct.SubImgUrls.push(response[0]);
                } else if ($("#uploadFlag").val() == 0) {
                    $scope.NormalSaleProduct.ImgUrl = response[0];
                }
                $("#fileInput").val("");
                //  console.info('onSuccessItem', fileItem, response, status, headers);
            };
            uploader.onErrorItem = function (fileItem, response, status, headers) {
                //  console.info('onErrorItem', fileItem, response, status, headers);
            };
            uploader.onCancelItem = function (fileItem, response, status, headers) {
                // console.info('onCancelItem', fileItem, response, status, headers);
            };
            uploader.onCompleteItem = function (fileItem, response, status, headers) {
                //  console.info('onCompleteItem', fileItem, response, status, headers);
            };
            uploader.onCompleteAll = function () {
                $scope.uploading = false;
            };

            //---------详情
            $scope.summernoteImgUpload = function sendFile(file) {
                var data = new FormData();
                data.append("file", file[0]);
                data.append("type", 0);
                data.append("FullUrl", true);
                $.ajax({
                    data: data,
                    type: "POST",
                    url: $rootScope.ImgUploadUrl + '?PlatForm=wsd&Path=Product',
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (response) {
                        $('.summernote').summernote('editor.insertImage', $rootScope.ImgHostUrl + response[0]);
                    }
                });
            }



            //// 日期插件
            //$scope.picker1 = {
            //    date: new Date()
            //};

            //$scope.datepickerOptions = {
            //    showWeeks: false,
            //    startingDay: 1,
            //    dateDisabled: function (data) {
            //        //return (data.mode === 'day' && (new Date().toDateString() == data.date.toDateString()));
            //    }
            //}

            //$scope.openCalendar = function (e, picker) {
            //    $scope[picker].open = true;
            //};


            $scope.ChooseFreightRadio = function () {
                if ($scope.NormalSaleProduct.SetFreightType == 0) {
                    $scope.NormalSaleProduct.FreightTemplateId = 0;
                    $("#choosefreighttemplate").attr("disabled", "disabled");
                    $("#uniformfreightinput").removeAttr("disabled");
                } else if ($scope.NormalSaleProduct.SetFreightType == 1) {
                    $scope.NormalSaleProduct.UniformFreight = "";
                    $("#uniformfreightinput").attr("disabled", "disabled");
                    $("#choosefreighttemplate").removeAttr("disabled");
                } else {
                    $scope.NormalSaleProduct.UniformFreight = "";
                    $scope.NormalSaleProduct.FreightTemplateId = 0;
                    $("#uniformfreightinput").attr("disabled", "disabled");
                    $("#choosefreighttemplate").attr("disabled", "disabled");
                }
            }

            $scope.GetFreightInfo = function (freightid) {
                $http.post("/Product/GetFreightInfo", { Id: freightid }).then(function (response) {
                    $scope.FreightInfo = response.data;
                });
            }
            $scope.refreshTemplate = function () {
                $http.post("/Product/GetFreightList").then(function (response) {
                    console.log(response)
                    $scope.FreightList = response.data.data;
                });
            }
            $scope.ChangeSpecType = function () {
                $http.post("/Product/ChangeSpecType", { Sku: $stateParams.Id, specTypeId: $scope.NormalSaleProduct.SpecTypeId }).then(function (response) {
                    $scope.SpecTemplateResponse = response.data.SpecTemplateResponse;
                    $scope.SpecList = response.data.SpecList;
                    $scope.ChooseSpecTemplateList = response.data.ChooseSpecTemplateList;
                    $scope.ChooseSpecItemList = response.data.ChooseSpecItemList;
                });
            }


            $scope.ChooseSpecItem = function (specitem) {
                var filterlist = $filter('filter')($scope.ChooseSpecItemList, function (item) { return item.Id === specitem.Id; });
                if (filterlist.length === 0) {
                    $scope.ChooseSpecItemList.push(specitem);
                } else {
                    console.log($scope.ChooseSpecItemList.indexOf(filterlist[0]));
                    $scope.ChooseSpecItemList.splice($scope.ChooseSpecItemList.indexOf(filterlist[0]), 1);
                }

                $http.post("/Product/ChooseSpecItem", { Sku: $stateParams.Id, chooseSpecItemList: $scope.ChooseSpecItemList }).then(function (response) {
                    $scope.SpecList = response.data.SpecList;
                    $scope.ChooseSpecTemplateList = response.data.ChooseSpecTemplateList;
                });


            }

            $scope.positionManagementView = function (groupid) {
                $http.post("/Product/GetAreaTree").then(function (returnData) {
                    console.log(returnData.data);
                    $scope.vm.treeData = returnData.data;
                    ngDialog.openConfirm({
                        template: 'getJurisdictionDialogId',
                        className: 'ngdialog-theme-plain',
                        scope: $scope
                    }).then(function (value) {
                    }, function (reason) {
                    });
                });
            }


            //树初始化
            $scope.vm = {
                treeData: [],
                treeConfig: {
                    core: {
                        multiple: true,
                        animation: true,
                        error: function (error) {
                            $log.error('treeCtrl: error from js tree - ' + angular.toJson(error));
                        },
                        check_callback: true,
                        worker: true
                    },
                    types: {
                        default: {
                            icon: 'fa fa-book'
                        },
                        star: {
                            icon: 'glyphicon glyphicon-star'
                        },
                        cloud: {
                            icon: 'glyphicon glyphicon-cloud'
                        }
                    },
                    version: 1,
                    plugins: ['types', 'checkbox']
                },
                applyModelChanges: function () {
                    return !$scope.vm.ignoreChanges;
                },
                setNodeType: function () {
                    var item = _.findWhere(this.treeData, { id: this.selectedNode });
                    item.type = this.newType;
                    toaster.pop('success', 'Node Type Changed', 'Changed the type of node ' + this.selectedNode);
                },
                readyCB: function () {
                    $timeout(function () {
                        $scope.vm.ignoreChanges = false;
                        toaster.pop('success', 'JS Tree Ready', 'Js Tree issued the ready event');
                    });
                },
                createCB: function (e, item) {
                    $timeout(function () { toaster.pop('success', 'Node Added', 'Added new node with the text ' + item.node.text) });
                }
            };


           

        }]);
</script>
